package com.tiantianfresh.model.dao;

import com.tiantianfresh.model.pojo.Commodity;
import com.tiantianfresh.model.pojo.CommodityResult;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author FANGAO
 * @date 2021/11/25 - 下午 17:22
 */
public interface CommodityMapper extends Mapper<Commodity> {
    /**
     * 商品展示
     * @return
     */
    @Select("select * from r_commodity ro left join r_commodity_allocation rca on ro.cid=rca.comid inner join r_categorygrouping rc on ro.catid = rc.crid where commodityorder=1 group by ro.cid order by price DESC")
    List<CommodityResult> queryAll();

    /**
     * 分类展示商品
     * @param id
     * @return
     */
    @Select("select * from r_commodity ro left join r_commodity_allocation rca on ro.cid=rca.comid inner join r_categorygrouping rc on ro.catid = rc.crid where commodityorder=1 and rca.caid=#{id}")
    CommodityResult queryCommodity(@Param("id") Integer id);

    /**
     * 商品展示
     * @return
     */
    List<CommodityResult> queryCommodityname();

    /**
     * 查询全部Commodity,返回list集合
     * @param crid
     * @return
     */
    @Select("select * from r_commodity where catid=#{catid}")
    List<Commodity> queryCommodityCatid(@Param("catid")Integer crid);

    /**
     * 根据id查询Commodity
     * @param id
     * @return
     */
    Commodity queryCommodityById(@Param("id") int id);

    /**
     * 根据id删除一个Commodity
     * @param id
     * @return
     */
    int deleteCommodityById(@Param("id") int id);

    /**
     * 添加一个Commodity
     * @param commodity
     * @return
     */
    int addCommodity(Commodity commodity);

    /**
     * 更新Commodity
     * @param commodity
     * @return
     */
    int updateCommodity(Commodity commodity);

    /**
     * 二级菜单子分类
     * @return
     */
    @Select("select * from r_commodity where catid=#{catid} and commodityorder=1 limit 0,5")
    List<Commodity> queryCatCommodity(@Param("catid") Integer catid);
}
